package net.seehealth.healthpad.ui.view;

import net.seehealth.healthpad.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;


public class GridItemView extends LinearLayout {

	/** 要显示在的上下文*/
	private Context mContext;
	
	/** 要显示的背景*/
	private LinearLayout mLayout;
	
	/** 显示的内容（上）*/
	private TextView mContentView;
	
	/** 显示的内容（下）*/
	private TextView mSubContentView;
	
	/** 显示的图标*/
	private ImageView mImageView;
	
	/** 每项item的id*/
	private int itemId;
	
	/**
	 * 构造方法
	 * @param context 当前上下文
	 * @param id item的id
	 * @param subShow 是否显示内容（下）
	 */
	public GridItemView(Context context, int id, boolean subVisiable) {
		super(context);
		mContext = context;
		itemId = id;
		
		initialize(subVisiable);
	}
	
	/**
	 * 初始化
	 */
	private void initialize(boolean subVisiable) {
		View view = LayoutInflater.from(mContext).inflate(
        		R.layout.grid_view_item, null); 
		mLayout = (LinearLayout) view.findViewById(R.id.ll_gridview_item);
		mLayout.getBackground().setAlpha(15);
		mImageView = (ImageView) view.findViewById(R.id.iv_gridview_item_img);
		mContentView = (TextView) view.findViewById(R.id.tv_gridview_item_content_top);
		mSubContentView = (TextView) view.findViewById(R.id.tv_gridview_item_content_bottom);
		
		if(subVisiable){
			mSubContentView.setVisibility(View.VISIBLE);
		} else{
			mSubContentView.setVisibility(View.GONE);
		}
		
		LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
				ViewGroup.LayoutParams.WRAP_CONTENT,
				ViewGroup.LayoutParams.WRAP_CONTENT);
		
		addView(view, lp);
	}
	
	/**
	 * 设置当前Item的值
	 * @param content 显示的内容
	 * @param img 背景色资源ID
	 * @param id Item项Id
	 */
	public void updateView(String content, int img, int id) {
		itemId = id;
		
		mContentView.setText(content);
		mImageView.setBackgroundResource(img);
	}

	public int getItemId() {
		return itemId;
	} 

}
